﻿using System;
using HarrisDesigns.Controls.dasBlogControls.Twitter;
using Microsoft.VisualStudio.TestTools.UnitTesting;

namespace dasBlogControls.Test.Twitter
{
    [TestClass]
    public class WhenAccessingStatusInformation
    {
        private Status _context;
        public Status Context
        {
            get
            {
                if (_context == null)
                {
                    _context = new Status();
                    _context.TimeStamp = "Thu Sep 10 14:03:38 +0000 2009";
                    _context.Text = @"I sent @someone to http://www.microsoft.com @ 5:00";
                }
                return _context;
            }
        }

        [TestMethod]
        public void ItShouldHaveTheExpectedCreationTime()
        {
            var timestamp = new DateTime(2009, 9, 10, 14, 03, 38, DateTimeKind.Utc);
            Assert.AreEqual(timestamp.ToLocalTime(), Context.Created);
        }
        [TestMethod]
        public void ItShouldConvertMentionsToLinks()
        {
            Console.WriteLine(Context.GetTextAsHtml());
            Assert.IsTrue(Context.GetTextAsHtml().Contains(@"I sent <a href=""http://twitter.com/someone/"">@someone</a> to "));
        }
        [TestMethod]
        public void ItShouldNotConvertStandaloneAtSignsToLinks()
        {
            Assert.IsTrue(Context.GetTextAsHtml().Contains(@" @ 5:00"));
        }
        [TestMethod]
        public void ItShouldConvertUrlsToLinks()
        {
            Assert.IsTrue(Context.GetTextAsHtml().Contains(@"to <a href=""http://www.microsoft.com"">http://www.microsoft.com</a> "));
        }
        [TestMethod]
        public void ItShouldHaveTheExpectedTimeDifference()
        {
            var statusTimestamp = new DateTime(2009, 9, 10, 14, 03, 38, DateTimeKind.Utc);
            var timeDiff = DateTime.Now - statusTimestamp.ToLocalTime();
            int daysDiff = (int) timeDiff.TotalDays;
            Assert.AreEqual(Context.GetTimeDifference(), String.Format("{0} days ago", daysDiff));
        }
    }
}